package com.huxiu.pagers;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.huxiu.R;
import com.huxiu.base.BasePager;
import com.huxiu.base.ZiXunDetailPager;
import com.huxiu.lib.PagerSlidingTab;
import com.huxiu.pagers.zixun.ShuoZhengJing;
import com.huxiu.pagers.zixun.TuiJian;
import com.huxiu.utils.UmenEvent;
import com.lidroid.xutils.ViewUtils;
import com.umeng.analytics.MobclickAgent;


public class NewscenterPager extends BasePager {
//    @ViewInject(R.id.search)
//    private ImageView search;//  首页的搜索现在先不用做

    public NewscenterPager(Context context) {
        super(context);
    }

    View view;

    @Override
    protected View init() {
        view = View.inflate(mContext, R.layout.newsdetail, null);
        ViewUtils.inject(this, view);
//        search.setVisibility(View.GONE);
        return view;
    }

    private PagerSlidingTab indicator;// 新闻详情里面的标题指针控件
    private ViewPager viewpager;// 新闻详情里面的ViewPager

    @Override
    public void initData() {
        indicator = (PagerSlidingTab) view.findViewById(R.id.indicator);
        viewpager = (ViewPager) view.findViewById(R.id.pager);
        // 给ViewPager设置数据
        viewpager.setAdapter(new MyAdapter());
        // 让指针控件绑定ViewPager
        indicator.setViewPager(viewpager);


    }

    String[] s = {"推荐", "说正经", "弄创潮", "早晚见", "耍腔调"};
    class MyAdapter extends PagerAdapter{
        // 返回标题
        @Override
        public CharSequence getPageTitle(int position) {
            return s[position];
        }

        @Override
        public int getCount() {
            return s.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        private ZiXunDetailPager pager;

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            switch (position) {
                case 0:
                    UmenEvent.UmengEventMap(mContext, UmenEvent.APP_HOME, UmenEvent.HOME_PAGECONTROL_TJ);
                    pager = new TuiJian(mContext);
                    container.addView(pager.rootView);
                    // 更新数据
                    pager.initData();
                    break;
                case 1:
                    UmenEvent.UmengEventMap(mContext, UmenEvent.APP_HOME, UmenEvent.HOME_PAGECONTROL_SZJ);
                    pager = new ShuoZhengJing(mContext, position);
                    container.addView(pager.rootView);
                    // 更新数据
                    pager.initData();
                    break;
                case 2:
                    UmenEvent.UmengEventMap(mContext, UmenEvent.APP_HOME, UmenEvent.HOME_PAGECONTROL_NCC);
                    pager = new ShuoZhengJing(mContext, position);
                    container.addView(pager.rootView);

                    // 更新数据
                    pager.initData();
                    break;
                case 3:
                    UmenEvent.UmengEventMap(mContext, UmenEvent.APP_HOME, UmenEvent.HOME_PAGECONTROL_ZWJ);
                    pager = new ShuoZhengJing(mContext, position);
                    container.addView(pager.rootView);
                    // 更新数据
                    pager.initData();
                    break;
                case 4:
                    UmenEvent.UmengEventMap(mContext, UmenEvent.APP_HOME, UmenEvent.HOME_PAGECONTROL_SQD);
                    pager = new ShuoZhengJing(mContext, position);
                    container.addView(pager.rootView);
                    // 更新数据
                    pager.initData();
                    break;
            }
            return pager.rootView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

    }
}
